async function* asyncGenerator() {
    for (let i = 1; i <= 3; i++) {
        // 模拟异步操作，每次迭代等待1秒
        await new Promise(resolve => setTimeout(resolve, 1000));
        yield i;
    }
}

// 使用异步迭代器生成一个异步迭代器对象
const asyncIterator = asyncGenerator();

// 使用 for await...of 遍历异步迭代器
(async () => {
    console.log("Start iterating...");
    try {
        // 遍历异步迭代器，等待每次迭代的 Promise 解析
        for await (const item of asyncIterator) {
            console.log("Received:", item);
        }
        console.log("Iteration completed!");
    } catch (error) {
        console.error("Error during iteration:", error);
    }
})();